package com.longxi.tianjintianbao.ui.adapter.multitype.work;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.longxi.tianjintianbao.AppConst;
import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.greedao.entity.Work;
import com.longxi.tianjintianbao.listener.AdapterListener;
import com.longxi.tianjintianbao.utils.MyUtils;

import me.drakeet.multitype.ItemViewBinder;
import q.rorbin.badgeview.Badge;
import q.rorbin.badgeview.QBadgeView;

/**
 * Created by cxw on 2018/2/20.
 */
public class WorkLayoutViewBinder extends ItemViewBinder<Work, WorkLayoutViewBinder.ViewHolder> {

    AdapterListener mListener;
    public WorkLayoutViewBinder(AdapterListener listener) {
        mListener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_work_layout, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull Work work) {
        holder.mIvImage.setImageResource(AppConst.mImage[new Long(work.getId()).intValue() - 1]);
        holder.mTvName.setText(MyUtils.getString(AppConst.mTitle[new Long(work.getId()).intValue() - 1]));
        if(work.getCategory() == 1){
            holder.mStOpenOrClose.setVisibility(View.GONE);
            holder.mIvImage.setBackgroundColor(MyUtils.getResource().getColor(R.color.colorPrimary));
        }else{
            holder.mStOpenOrClose.setVisibility(View.VISIBLE);
            holder.mIvImage.setBackgroundColor(MyUtils.getResource().getColor(R.color.white));
        }
        if(work.getIsVisible() == 1){
            holder.mStOpenOrClose.setChecked(true);
        }else{
            holder.mStOpenOrClose.setChecked(false);
        }
        holder.mStOpenOrClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mListener.onClick(holder.getAdapterPosition());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView mIvImage;
        TextView mTvName;
        Switch mStOpenOrClose;
        ViewHolder(View itemView) {
            super(itemView);
            mIvImage = itemView.findViewById(R.id.ivImage);
            mTvName = itemView.findViewById(R.id.tvName);
            mStOpenOrClose = itemView.findViewById(R.id.stOpenOrClose);
        }
    }
}
